/**
 * @fileOverview 事件类型资源
 * @author goodzsq@gmail.com
 */

//match string: function xxx(){}
var funRegExp = /^\s*function\b\s*[^\(]*\([^\)]*\)\s*\{.*\}\s*$/;

var DataType = {
    serialize: function(v) {
        return String(v);
    },
    parse: function(v) {
        return String(v);
    },
    load: function(v) {
        if (typeof v === 'string') {
            if (!funRegExp.test(v)) {
                return null;
            }
            var fun;
            try {
                eval('fun = ' + v);
            } catch (e) {
                return null;
            }
            return fun;
        } else {
            return null;
        }
    },
    save: function(v) {
        if (typeof v === 'function') {
            return String(v);
        } else {
            return null;
        }
    }
};

module.exports = DataType;